<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include :: header('婚庆公司管理')" />
</head>
<body class="gray-bg">
	<div class="container-div">
		<div class="row">
			<div class="col-sm-12 search-collapse">
				<form id="post-form">
					<div class="select-list">
						<ul>
							<li>
								公司名称：<input type="text" name="companyName"/>
							</li>
							<li>
								账号状态：<select name="companyState" th:with="type=${@dict.getType('sys_normal_disable')}">
								<option value="-1">全部</option>
								<option value="1">正常</option>
								<option value="0">未审核</option>
								<option value="2">禁用</option>
							</select>
							</li>
							<li>
								订单量：<select name="companyOrderVolumeOrderNum" th:with="type=${@dict.getType('sys_normal_disable')}">
									<option value="-1">默认</option>
									<option value="1">订单量降序排列</option>
									<option value="2">订单量升序排列</option>

								</select>
							</li>
							<li>
								<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
							    <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
							</li>
						</ul>
					</div>
				</form>
			</div>
			
			<div class="btn-group-sm" id="toolbar" role="group">
				<a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="user:company:add">
	                <i class="fa fa-plus"></i> 新增
	            </a>
				<a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="user:company:edit">
		            <i class="fa fa-edit"></i> 修改
		        </a>
				<a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="user:company:remove">
		            <i class="fa fa-remove"></i> 删除
		        </a>
				<a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="user:company:export">
		            <i class="fa fa-download"></i> 导出
		        </a>
	        </div>
	        
	        <div class="col-sm-12 select-table table-striped">
			    <table id="bootstrap-table"></table>
			</div>
		</div>
	</div>
	<th:block th:include="include :: footer" />
	<script th:inline="javascript">
		var editFlag = [[${@permission.hasPermi('user:company:edit')}]];
		var removeFlag = [[${@permission.hasPermi('user:company:remove')}]];
		var changeFlag = [[${@permission.hasPermi('user:company:state')}]];
		var PlannerFlag = [[${@permission.hasPermi('user:company:list')}]];
		var datas = [[${@dict.getType('sys_normal_disable')}]];
		var prefix = ctx + "user/company";

		$(function() {
		    var options = {
		        url: prefix + "/list",
		        createUrl: prefix + "/add",
		        updateUrl: prefix + "/edit/{id}",
		        removeUrl: prefix + "/remove",
		        exportUrl: prefix + "/export",
		        sortName: "companyId",
		        modalName: "婚庆公司",
		        columns: [{
		            checkbox: true
		        },
		        {
		            field: 'companyId',
		            title: '编号',
					sortable: true
		        },
		        {
		            field: 'companyName',
		            title: '公司名称'
		        },
		        {
		            field: 'companyPhone',
		            title: '法人手机号',
		        },
		        {
		            field: 'companyEmail',
		            title: '公司邮箱',
		        },
		        {
		            field: 'companyDate',
		            title: '开通时间',
		            sortable: true
		        },
		        {
		            field: 'companyOrderVolume',
		            title: '订单量',
		        },

		        {
		            field: 'companyState',
		            title: '账号状态',
		            align: 'center',
		            formatter: function(value, row, index) {
		            	if(value == 0){
		            		return "<span style=' color: red'>未审核</span>";
						}else if(value == 2){
		            		return "<span style=' color: red'>禁用</span>";
						}else{
		            		return "正常";
						}
		            }
		        },
		        {
		            title: '操作',
		            align: 'center',
		            formatter: function(value, row, index) {
		                var actions = [];
		                actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.companyId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
		                actions.push('<a class="btn btn-primary btn-xs ' + PlannerFlag + '" href="javascript:void(0)" onclick="checkCompanyPlanner('+row.companyId+')"><i class="fa fa-table"></i>策划师列表</a> ');
		                if(row.companyState == 0){
							actions.push('<a class="btn btn-warning btn-xs ' + changeFlag + '" href="javascript:void(0)" onclick="checkCompanyState(this,' + row.companyId + ','+row.companyState+')">账号审核</a>');
						}else if(row.companyState == 2){
							actions.push('<a class="btn btn-info btn-xs ' + changeFlag + '" href="javascript:void(0)" onclick="checkCompanyState(this,' + row.companyId + ','+row.companyState+')">账号恢复</a>');
						}else{
							actions.push('<a class="btn btn-danger btn-xs ' + changeFlag + '" href="javascript:void(0)" onclick="checkCompanyState(this,' + row.companyId + ','+row.companyState+')">账号禁用</a>');
						}

		                return actions.join('');
		            }
		        }]
		    };
		    $.table.init(options);
		});

		//修改状态
		function checkCompanyState(obj, companyId, companyState) {

			if(companyState == 2){
				companyState =1;
			}else if(companyState == 1){
				companyState =2;
			}else{
					companyState=1;
				}



			$.post(prefix + "/ChangeState",{companyId:companyId,companyState:companyState},function (result) {
				if(result.code==0){
					$.table.refresh();
				}else{
					$.modal.msgSuccess("操作失败");
				}
			},"json")

		}

		function checkCompanyPlanner(companyId) {
			var url = prefix + '/planner/'+companyId;
			$.modal.open("策划师列表", url);
		}

	</script>
</body>
</html>